Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

/**
 * 获取当前年份的第一天和最后一天
 * @returns {string} 例如 2019-01-01~2019-12-31
 */
export function getYearFirstLastDay() {
  var firstDay = new Date();
  firstDay.setDate(1);
  firstDay.setMonth(0);
  var lastDay = new Date();
  lastDay.setFullYear(lastDay.getFullYear() + 1);
  lastDay.setDate(0);
  lastDay.setMonth(-1);
  firstDay = firstDay.Format("yyyy-MM-dd");
  lastDay = lastDay.Format("yyyy-MM-dd");
  return {
    firstDay,
    lastDay,
  };
}

/**
 * 获取当前月份的第一天和最后一天
 * @returns {string}  例如 2019-09-01~2019-09-30
 */
export function getMonthFirstLastDay() {
  var myDate = new Date();
  var currentMonth = myDate.getMonth();
  var firstDay = new Date(myDate.getFullYear(), currentMonth, 1);
  var lastDay = new Date(firstDay.getFullYear(), currentMonth + 1, 0);
  firstDay = firstDay.Format("yyyy-MM-dd");
  lastDay = lastDay.Format("yyyy-MM-dd");
  return {
    firstDay,
    lastDay,
  };
}
/**
 * 获取当前星期的第一天和最后一天
 * @returns {string} 例如 2019-09-09~2019-09-15
 */
export function getWeekFirstLastDay() {
  var current = new Date();
  var currentyear = current.getFullYear();
  var currentMonth = current.getMonth();
  var currentDay = current.getDay();
  var currentDate = current.getDate();
  var firstDay = new Date(
    currentyear,
    currentMonth,
    currentDate - currentDay + 1
  );
  var lastDay = new Date(
    currentyear,
    currentMonth,
    currentDate + (6 - currentDay + 1)
  );
  firstDay = firstDay.Format("yyyy-MM-dd");
  lastDay = lastDay.Format("yyyy-MM-dd");
  return {
    firstDay,
    lastDay,
  };
}

export function formatTime(time,formatter = "yyyy-MM-dd") {
  return new Date(time).Format(formatter)
}